<?php
class staticpages_edit extends SClass {

    public function process() {
    	try {
    		$staticpage = ServiceUtils::GetFactory()->getStaticpageService()->getStaticpageByUrl(
    			$this->getArgument('url')
    		);
			if ($this->getControlValue('save')) {
				ServiceUtils::GetFactory()->getStaticpageService()->editStaticpage(
					$this->getArgument('url'),
					$this->getControlValue('title'),
					$this->getControlValue('content'),
					$this->getControlValue('url')
				);
				$this->assign (
					'page_view',
					Engine_LinkMaker::GetURLByContentID(
						'controlpanel-staticpages-view',
						$this->getControlValue('url'),
						'url')
					);
				$this->assign ('message', 'ok');
			} else {
				$this->setControlValue('title', $staticpage->getTitle());
				$this->setControlValue('content', $staticpage->getContent());
				$this->setControlValue('url', $staticpage->getUrl());
			}
		} catch (ServiceUtils_Exception $exception) {
			$this->assign ('errors', $exception->getErrors());
		}
    }

}